﻿using System;
using System.Diagnostics;
using System.IO;
using System.Windows.Forms;
using Assist;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using DBService;

namespace YJKArch.RoomRoofModule
{
	[Transaction(TransactionMode.Manual)]
	[Regeneration(RegenerationOption.Manual)]
	internal class CmdRoomInfoShare : IExternalCommand
	{
		public Result Execute(ExternalCommandData cmdData, ref string messages, ElementSet elements)
		{
			UIApplication application = cmdData.Application;
            Autodesk.Revit.ApplicationServices.Application application2 = application.Application;
			Autodesk.Revit.DB.Document document = application.ActiveUIDocument.Document;
			try
			{
				Process currentProcess = Process.GetCurrentProcess();
				if (currentProcess != null)
				{
					DlgSynergyType dlgSynergyType = new DlgSynergyType();
					dlgSynergyType.ReadDlgData("RoomInfoShare");
					if (dlgSynergyType.ShowDialog() == DialogResult.OK)
					{
						dlgSynergyType.SaveDlgData("RoomInfoShare");
						bool flag = false;
						if (dlgSynergyType.SynergyType == 0)
						{
							flag = false;
						}
						else if (dlgSynergyType.SynergyType == 1)
						{
							flag = true;
						}
						WindowHandle owner = new WindowHandle(currentProcess.MainWindowHandle);
						if (!flag && !File.Exists(dlgSynergyType.FileName))
						{
							try
							{
								XmlUtils.CreateDataFile(dlgSynergyType.FileName);
							}
							catch (Exception ex)
							{
								messages = ex.Message;
								return Autodesk.Revit.UI.Result.Failed;
							}
						}
						DlgRoomInfo.GetInstance(cmdData, flag, dlgSynergyType.FileName).Show(owner);
					}
				}
				else
				{
					MessageBox.Show("未能得到当前Revit进程！", "盈建科提示");
				}
			}
			catch (Exception ex2)
			{
				TaskDialog.Show("error", ex2.ToString());
			}
			return Autodesk.Revit.UI.Result.Succeeded;
		}
	}
}
